import * as types from "./mutation-types";
import Api from "api/api";
const state = {
  discusss: {},
  currentDiscuss: {}
};

const getters = {
  discusss: state => state.discusss,
  currentDiscuss: state => state.currentDiscuss
};

const actions = {
  getDiscussPageS({ commit }, param) {
    return Api.getDiscussPage(param).then(ret => {
      commit(types.UPDATE_DISCUSSS, ret.data.data);
      return ret;
    });
  },
  getDiscussS({ commit }, id) {
    return Api.getDiscuss({ id: id }).then(ret => {
      console.log(ret.data.data);
      commit(types.UPDATE_CURRENT_DISCUSS, ret.data.data);
      return ret;
    });
  },
  addOrUpdateDiscussS({ commit }, payload) {
    return Api.addOrUpdateDiscuss({ body: payload }).then(ret => {
      return ret;
    });
  },
  deleteDiscussS({ commit }, param) {
    console.log(param);
    return Api.deleteDiscuss(param).then(ret => {
      return ret;
    });
  }
};

const mutations = {
  [types.INIT_CURRENT_DISCUSS](state, payload) {
    state.currentDiscuss = {
      name: "",
      deptId: payload.departId,
      deptName: payload.departName
    };
  },
  [types.UPDATE_DISCUSSS](state, payload) {
    state.discusss = payload;
  },
  [types.UPDATE_CURRENT_DISCUSS](state, payload) {
    state.currentDiscuss = payload;
  }
};
export default {
  state,
  getters,
  actions,
  mutations
};
